/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.GUI.archive;

import ac.ui.utils;
import ac.uitls.propertiesOperation;

/**
 *
 * @author empcl_000
 */
public class updateBalenc extends ac.ui.controls.PCLFrame {

    ac.engin.archive.Products p = new ac.engin.archive.Products();
    ac.engin.archive.clients c = new ac.engin.archive.clients();
    propertiesOperation po = new propertiesOperation();
    /**
     * Creates new form comboBoxadds
     */
    String id = "";
    String Type = "";
    double B = 0;

    public updateBalenc(String type, String id) {
        initComponents();
        onLoad();

        this.id = id;
        this.Type = type;
        B = getData();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jCheckBox2 = new javax.swing.JCheckBox();
        pCLCheckBoxBeanInfo1 = new ac.ui.controls.PCLCheckBoxBeanInfo();
        pCLCheckBoxBeanInfo2 = new ac.ui.controls.PCLCheckBoxBeanInfo();
        right_panel = new ac.ui.controls.PCLPanel();
        pCLToolbar2 = new ac.ui.controls.PCLToolbar();
        jbt_add = new ac.ui.controls.PCLButton();
        pCLSeperator1 = new ac.ui.controls.PCLSeperator();
        jtxt_title = new ac.ui.controls.PCLTextField();
        pCLLabel5 = new ac.ui.controls.PCLLabel();
        pCLLabel7 = new ac.ui.controls.PCLLabel();
        pCLMoney1 = new ac.ui.controls.PCLMoney();

        jCheckBox2.setText("jCheckBox2");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setAlwaysOnTop(true);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                formKeyTyped(evt);
            }
        });

        pCLToolbar2.setRollover(true);

        jbt_add.setType("add");
        jbt_add.setFocusable(false);
        jbt_add.setText("jbt_add");
        jbt_add.setVerticalTextPosition(3);
        jbt_add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbt_addActionPerformed(evt);
            }
        });
        pCLToolbar2.add(jbt_add);

        pCLSeperator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        pCLToolbar2.add(pCLSeperator1);

        jtxt_title.setRequired(true);

        pCLLabel5.setText("jtxt_title");

        pCLLabel7.setText("jtxt_title");

        javax.swing.GroupLayout right_panelLayout = new javax.swing.GroupLayout(right_panel);
        right_panel.setLayout(right_panelLayout);
        right_panelLayout.setHorizontalGroup(
            right_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pCLToolbar2, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
            .addGroup(right_panelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(right_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pCLLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pCLLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(right_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pCLMoney1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jtxt_title, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        right_panelLayout.setVerticalGroup(
            right_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, right_panelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(right_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxt_title, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pCLLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(right_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pCLLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pCLMoney1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                .addComponent(pCLToolbar2, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(right_panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(right_panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    double getData() {

        String t = "";
        double b = 0;

        t = c.getRow(id)[1];
        b = c.getbalance(id);

        jtxt_title.setText(t + " - " + b + "");
        this.setTitle(t + " - " + b + "");

        return b;
    }

    void updatData() {

        String t = "";
        B = getData();
        if (B > 0 || this.Type == null) {

            utils.sendError(this, po.getWord("label.error"), po.getWord("message.errorHaveBalenc"));
            this.setVisible(false);
            this.dispose();

        } else {

            double d = pCLMoney1.getVal();
            c.addTobalance(id, d);

            utils.sendSaveMssage(this);
            this.setVisible(false);
            this.dispose();
        }

    }
    private void jbt_addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbt_addActionPerformed

        updatData();
    }//GEN-LAST:event_jbt_addActionPerformed

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed

    }//GEN-LAST:event_formKeyPressed

    private void formKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyTyped

    }//GEN-LAST:event_formKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(updateBalenc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(updateBalenc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(updateBalenc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(updateBalenc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new updateBalenc("", "").setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox jCheckBox2;
    private ac.ui.controls.PCLButton jbt_add;
    private ac.ui.controls.PCLTextField jtxt_title;
    private ac.ui.controls.PCLCheckBoxBeanInfo pCLCheckBoxBeanInfo1;
    private ac.ui.controls.PCLCheckBoxBeanInfo pCLCheckBoxBeanInfo2;
    private ac.ui.controls.PCLLabel pCLLabel5;
    private ac.ui.controls.PCLLabel pCLLabel7;
    private ac.ui.controls.PCLMoney pCLMoney1;
    private ac.ui.controls.PCLSeperator pCLSeperator1;
    private ac.ui.controls.PCLToolbar pCLToolbar2;
    private ac.ui.controls.PCLPanel right_panel;
    // End of variables declaration//GEN-END:variables
}
